package com.example.demo.controller;

import com.example.demo.entity.Kitting.*;
import com.example.demo.services.KittingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/kitting")
public class KittingController {

    @Autowired
    private KittingService service;

    @PostMapping("/getProduct")
    public KittingProductDTO getProduct(@RequestBody Map<String, String> payload) {
        String productCode = payload.get("productCode");
        String waCode = payload.get("waCode");
        return service.getProduct(productCode, waCode);
    }

    @PostMapping("/getProductPDF")
    public String getProductPDF(@RequestBody Map<String, String> payload) {
        String productCode = payload.get("productCode");
        return service.getProductPDf(productCode);
    }

    @PostMapping("/queryWaCode")
    public List<KittingWA> queryWaCode(@RequestBody Map<String, String> payload) {
        String userID = payload.get("userID");
        String property = payload.get("property");
        return service.queryWaCode(userID, property);
    }

    @PostMapping("/addStorageArea")
    public int addStorageArea(@RequestBody Map<String, String> payload) {
        String productBillNo = payload.get("productBillNo");
        String userID = payload.get("userID");
        String waCode = payload.get("waCode");
        String qty = payload.get("inQty");
        String overInQty = payload.get("overInQty");
        return service.addStorageArea(userID, productBillNo, waCode, qty, overInQty);
    }

    @PostMapping("/getQty")
    public KittingQty getQty(@RequestBody Map<String, String> payload) {
        String goodsCode = payload.get("goodsCode");
        String productCode = payload.get("productCode");
        String productBillNo = payload.get("productBillNo");
        return service.getQty(goodsCode, productCode, productBillNo);
    }

    @PostMapping("/getList")
    public List<Map<String, Object>> getKittingGoodsList(@RequestBody Map<String, String> payload) {
        String productBillNo = payload.get("productBillNo");
        return service.getKittingGoodsList(productBillNo);
    }

    @PostMapping("/onQty")
    public int onQty(@RequestBody Map<String, String> payload) {
        String productBillNo = payload.get("productBillNo");
        return service.onQty(productBillNo);
    }
    /* 组件齐套 暂无用*/
    @PostMapping("/getProductCode")
    public String getProductCode(@RequestBody Map<String, String> payload) {
        String productBillNo = payload.get("productBillNo");
        return service.getProductCodeByBillNo(productBillNo);
    }

    @PostMapping("/getWpSchedule")
    public List<KittingWp> getWpSchedule(@RequestBody Map<String, String> payload) {
        String billNo = payload.get("billNo");
        return service.getWpSchedule(billNo);
    }

    @PostMapping("/getImageUrl")
    public String getImageUrl(@RequestBody Map<String, String> payload) {
        String goodsCode = payload.get("goodsCode");
        return service.getImageUrl(goodsCode);
    }
}
